<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>async应用</title>
</head>
<script>
    // 基于promise的异步操作的封装
    function request(url) {
        return new Promise((resolve,reject) => {
            var xhr = new XMLHttpRequest();
            xhr.open('get',url)
            xhr.send();
            xhr.responseType = 'json'
            xhr.onreadystatechange = function() {
                if(this.readyState == 4) {
                    if(this.status == 200) {
                        resolve(this.response)
                    }else {
                        reject(this.reject)
                    }
                }
            }
        })
    }

    async function findAllCategory() {
        let categories = await request('http://39.96.21.48:5588/category/findAll');
        console.log(categories)
    }
    findAllCategory()
</script>
<body>
    
</body>
</html>